package com.gewu.pm.ui.adapter.home;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.TestBean;

/**
 * 月度汇总表格适配器
 * 使用 TestBean 存储员工考勤数据
 * 
 * TestBean 字段说明：
 * - id: 员工ID
 * - name: 员工姓名
 * - type: 考勤数据（JSON格式，包含部门、出勤天数等信息）
 */
public class MonthlyTableAdapter extends AppAdapter<TestBean> {

    public MonthlyTableAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    /**
     * 表格行 ViewHolder
     */
    private final class ItemViewHolder extends AppAdapter<TestBean>.ViewHolder {

        private final TextView mNameView;
        private final TextView mDepartmentView;
        private final TextView mAttendanceDaysView;
        private final TextView mNormalDaysView;
        private final TextView mStartDateView;
        private final TextView mEndDateView;
        private final TextView mUnsignedDaysView;
        private final TextView mUnsignedOutDaysView;
        private final TextView mEarlyLeaveDaysView;
        private final TextView mLateDaysView;
        private final TextView mAbsentDaysView;
        private final TextView mNoPunchDaysView;

        private ItemViewHolder() {
            super(R.layout.item_monthly_table_row);
            
            // 初始化所有字段
            mNameView = findViewById(R.id.tv_name);
            mDepartmentView = findViewById(R.id.tv_department);
            mAttendanceDaysView = findViewById(R.id.tv_attendance_days);
            mNormalDaysView = findViewById(R.id.tv_normal_days);
            mStartDateView = findViewById(R.id.tv_start_date);
            mEndDateView = findViewById(R.id.tv_end_date);
            mUnsignedDaysView = findViewById(R.id.tv_unsigned_days);
            mUnsignedOutDaysView = findViewById(R.id.tv_unsigned_out_days);
            mEarlyLeaveDaysView = findViewById(R.id.tv_early_leave_days);
            mLateDaysView = findViewById(R.id.tv_late_days);
            mAbsentDaysView = findViewById(R.id.tv_absent_days);
            mNoPunchDaysView = findViewById(R.id.tv_no_punch_days);
        }

        @Override
        public void onBindView(int position) {
            TestBean item = getItem(position);
            
            // 设置员工基本信息
            mNameView.setText(item.getName());
            
            // 解析 type 字段中的考勤数据（这里使用模拟数据）
            // 实际项目中可以将 type 字段存储为 JSON，然后解析
            String employeeId = item.getId();
            
            // 模拟数据展示
            mDepartmentView.setText("销售部");
            mAttendanceDaysView.setText("22");
            mNormalDaysView.setText("20");
            mStartDateView.setText("2025年8月1日");
            mEndDateView.setText("2025年8月31日");
            mUnsignedDaysView.setText("1");
            mUnsignedOutDaysView.setText("1");
            mEarlyLeaveDaysView.setText("1");
            mLateDaysView.setText("1");
            mAbsentDaysView.setText("1");
            mNoPunchDaysView.setText("1");
        }
    }
}
